<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="/misc/css/base.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/btnicon.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/reset_admin.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/adminmenu.css"  />
<link rel="stylesheet" type="text/css" href="/misc/css/newadmin.css"  />
<script type="text/javascript" src="/misc/vendors/jquery/jquery_1.2.6.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js.js"></script>
<script type="text/javascript" src="/misc/vendors/o2js/o2js_build.js"></script>
<script type="text/javascript" >
var baseUrl = "<?=$themeUrl?>";
$().ready(function(){



});
var grids;
</script>


<title></title> 
<style type="text/css">
/* reset.css */
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;padding:0;}
table {
border-collapse:collapse;border-spacing:0;}
fieldset,img{
border:0;}
address,caption,cite,code,dfn,em,strong,th,var {
font-style:normal;font-weight:normal;}
ol,ul {
list-style:none;}
caption,th {
text-align:left;}
q:before,q:after {
content:'';}
abbr,acronym {
 border:0;}
html,body{
font-size:12px;font-family:"宋体",Arial,Helvetica,sans-serif;}
/* 整体效果 */
body{
background-color:#FCFCFC;
 
}

/* 搜索框 */
.search-box{
margin:1px;
}
/* 底部按钮 */
.search-btn{
margin:0px;
padding:0px;
text-align:center;
}
/* 查询框 */
#searchKey{
  
width: 600px;
font-size:12px;
color:#333333;
}


/* 大体结构 */
table.resulttb{
width:100%;
border-collapse:collapse;
}
table.resulttb td.resulttb_td{
padding:0px;
margin:0px;
border:0px solid #CCCCCC;
background-color:#FFFFFF;
text-align:left;
vertical-align:top;
}
/* 左侧分组 */
ul.resulttd_ul{
margin:0px;
padding:0px;
background-color:#F6F9FE;
height:260px;
overflow-y:auto;
overflow-x:hidden;
}
ul.resulttd_ul li{
list-style:none;
display:block;
margin:0px!important;
padding:0px!important;
width:120px;
}
ul.resulttd_ul li a{
display:block;
width:120px;
padding:3px;
color:#999999;
text-decoration:none!important;
margin:0px!important;
}
ul.resulttd_ul li a.on,ul.resulttd_ul li a:hover{
background-color:#CDE3F8;
text-decoration:none;
color:#FFFFFF;
}


/* 通用表格 */
table.manytable{
border: 1px solid #C7CDD4;
border-collapse: collapse;
width: 100%;
}
table.manytable thead td.tdtitle{
background: url("/misc/images/manytable.gif") repeat-x scroll center bottom #FFFFFF;
 
color: #185A80;
font-size: 12px;
font-weight: bold;
text-align:center; 
padding:2px; 
background-color:#FFFFFF;
border:1px solid #C7CDD4;
}
table.manytable tbody td{
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
padding: 2px; 
text-align:center;
color:#333333;
font-size:12px;
}
table.manytable tbody td.even{
background-color:#F5F5F5;
}
 
</style>
</head>
<body> 
<div class="search-box"  style="overflow: hidden; vertical-align: top;">
	<input type="text" id="searchKey" title="请输入查询关键字"  class="searchs"  value="" maxlength="100"/>
	&nbsp;&nbsp;
	<button onclick="fnBeginSearch()" >搜索</button> 
</div>
 

<div style="margin:2px">
	<table class="resulttb">
		<tr>
			<td class="resulttb_td" style="width:130px;background-color:#F6F9FE;">
				<div style="margin:10px auto">
					<select class="textBox" id="state" onchange="fnSearyByGroup()">
						<option value="">--所有账户状态--</option>
						<option value="0" >意向客户</option>
						<option value="1" selected="selected">会员</option>
						<option value="2" >暂停</option>
						<option value="3" >取消</option>
					</select>	
				</div>	
				<div style="margin:10px auto">
					<select class="textBox" id="sendtype" onchange="fnSearyByGroup()">
						<option value=""  selected="selected">--所有配送类别--</option>
						<option value="0" >乐园卡</option>
						<option value="1">田园卡</option>
					</select>	
				</div>	
				<div style="margin:10px auto">
					<select class="textBox" id="sendweek" onchange="fnSearyByGroup()">
						<option value="">--所有配送日期--</option>
						<?PHP
						if(is_array($rs_group) && count($rs_group)>0){
							foreach($rs_group as $k=>$v){ 
								echo '
							<option value="'.$v.'" >'.$v.'</option>
								';
							}
						}
						?>
					</select>
				</div>
				<div style="margin:10px auto">
					<select class="textBox" id="classes" onchange="fnSearyByGroup()">
						<option value="">--所有会员类型--</option>
						<?PHP
						if(is_array($rs_classes) && count($rs_classes)>0){
							foreach($rs_classes as $k=>$v){ 
								echo '
							<option value="'.$v['id'].'" >'.$v['val'].'</option>
								';
							}
						}
						?>
					</select>
				</div>
			</td>
			<td class="resulttb_td">
				<div style="height:225px;overflow-y:auto">
					<!--联系人列表-->
					<table class="manytable" >
						<thead>
							<tr>
								<td class="tdtitle" style="width:20px;" ><input type="checkbox" class="allck" id="allck" title="全选" onclick="fnSltAll()" /></td> 
								<td class="tdtitle" >类型</td>
								<td class="tdtitle" >编号</td>
								<td class="tdtitle" >姓名</td>
								<td class="tdtitle" >配送类别</td>
								<td class="tdtitle" >配送频次</td>
								<td class="tdtitle" >服务截止</td>
								<td class="tdtitle" >状态</td>
							</tr>
						</thead>	
						<tbody id="tbnobody" style="overflow-y:auto;display:none">
							<tr>
								<td class="tdvalue" colspan="6" style="text-align:center">
									没有找到任何信息
								</td>
							</tr>
						</tbody>
						<tbody id="tbloading" style=" overflow-y:auto;display:none">
							<tr>
								<td class="tdvalue" colspan="6" style="text-align:center">
									<img src="/misc/images/loading.gif" title="正在加载" />
								</td>
							</tr>
						</tbody>	
						<tbody id="tbdata" style=" display: "> 
							 
						</tbody>	
					</table>	
				</div>	
				<div id="grids" style="background-color:#FFFFFF;border-top:0px solid #CCCCEE;"></div>
			 
			</td>
		</tr> 
	</table> 
</div>
<div style="padding:4px;background-color:#CCE1FE;border:0px solid #CCCCCC;color:#666666">
	已选会员：（点击已选会员即可移除选择） 
	<a href="javascript:void(0)"  style="color:red" onclick="fnCancelSelect()">清空选择</a>
</div>
<style type="text/css">
#selectinfo_div a.selectinfo_a{
float:left;
padding:3px;
border:1px solid #B2D9F0;
color:#0082CB;
margin:1px;
text-decoration:none;
}
#selectinfo_div a.selectinfo_a:hover{
text-decoration:line-through;
color:#666666;
background-color:#FFE8E8
}
#selectinfo_div a.contactman{

/* padding-left:20px; */
}
</style>
<div id="selectinfo_div" style="height:100px;border:1px solid #CCCCCC;padding:2px;overflow:auto;background-color:#FFFFFF">  
</div>
<div style="clear:both;height:0px;line-height:0p;"></div>
<div class="search-btn" > 
	<button class="" onclick="fnOnSlt()">确定选择</button> 
	<span class="gray">或</span>
	<a href="javascript:void(0)"  class="cancel" onclick="fnCancel()">取消</a>
</div>
<script type="text/javascript">
var url_list = '/selection/usermany';
var funcname = "<?=$funcname?>";  //回调函数   
var grids;//表格对象
var key = '';//缓存关键字 
var results;//缓存的数据 
 


/* 选择参数 */

var contact_ids = []; //选择的联系人ID集合

$().ready(function(){ 
	o2js.build('o2grid');
	grids = new o2Grid({
		bind:'grids', 
		url:url_list,
		imgpath:'/misc/vendors/o2js/o2grid/image',
		rowNum:10,
		beforefunc:function(){
			$('#tbdata').hide(); 
			$('#tbnobody').hide(); 
			$('#tbloading').show();
		},
		runfunc:function(obj){ 
			if(obj.results.length == 0){
				$('#tbdata').hide();
				$('#tbloading').hide();
				$('#tbnobody').show();
			}else{
				$('#tbloading').hide();
				$('#tbnobody').hide();
				$('#tbdata').show();
			}
			fnLoadEnd(obj.results);
		} 
	});
	 
	$('#searchKey').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnBeginSearch();
		}
	});
	 
	fnSearyByGroup();
	
});
/* 关键词搜索 */
function fnBeginSearch(){
	
	$('#a_allcontact').removeClass('on');
	$('.a_group').removeClass('on'); 
  
	grids.setBaseParams({
		keywords:$.trim($('#searchKey').val()),
		type_id:'',
		loadtype:'search'
	});
	grids.load(1); 
}
/* 搜索全部联系人 */
function fnSearchAll(){ 
	$('#a_allcontact').addClass('on');
	$('.a_group').removeClass('on'); 
	  
	grids.setBaseParams({
		keyword:'',
		type_id:'',
		loadtype:'all'
	});
	grids.load(1); 
} 


/* 筛选搜索 */
function fnSearyByGroup(){
	grids.setBaseParams({
		keyword:'',
		state:$('#state').val(),
		sendweek:$('#sendweek').val(),
		classes:$('#classes').val(),
		sendtype:$('#sendtype').val(),
		loadtype:'group'
	});
	grids.load(1);
}

/* 暂时可能没用到了 */
function fnSearchByClasses(id,val){
	$('#a_allcontact').removeClass('on');
	$('.a_group').removeClass('on'); 
	$('#a_classes_'+id).addClass('on');
	grids.setBaseParams({
		keyword:'',
		classes:id,
		loadtype:'classes'
	});
	grids.load(1);
}



/* 数据加载完，进行组装显示 */
function fnLoadEnd(objs){
	results = objs;  
	var html='';
	for(var i=0; i<objs.length; i++){
		var obj = objs[i];
		var even = '';
		if(i%2 == 1){
			even = 'even';
		}
		html += '<tr class="simpleinfotr" style="cursor:pointer" id="simpleinfotr_'+obj.id+'" indexes="'+obj.id+'"  onclick="fnSltOne('+i+','+obj.id+')" >';
		html += '	<td class="tdvalue '+even+'" >';
		html += '		<input type="checkbox" class="contactck" id="slt_'+obj.id+'" onclick="fnSltOne_ckb('+i+','+obj.id+');"  contact_id="'+obj.id+'" myindex="'+i+'" />';
		html += '	</td>'; 
		html += '	<td class="tdvalue '+even+'"  title="'+obj.classes+'"> '+obj.classes+' </td>';
		html += '	<td class="tdvalue '+even+'"  title="'+obj.username+'"> '+obj.username+' </td>';
		html += '	<td class="tdvalue '+even+'"  title="'+obj.name+'"> '+obj.name+' </td>';
		if(obj.sendtype == '0'){
			obj.sendtype = '乐园卡';
		}else{
			obj.sendtype = '田园卡';
		}
		html += '	<td class="tdvalue '+even+'"  title="'+obj.sendtype+'"> '+obj.sendtype+' </td>';
		html += '	<td class="tdvalue '+even+'"  title="'+obj.phone+'">'+obj.sendweek1+','+obj.sendweek2+'</td>';
		html += '	<td class="tdvalue '+even+'"  title="'+obj.edate+'">'+obj.edate+'</td>'; 
		
		if(obj.state == '0'){
			obj.state = '意向客户';
		}else if(obj.state == '1'){
			obj.state = '会员';
		}else if(obj.state == '2'){
			obj.state = '暂停';
		}else{
			obj.state = '取消';
		}
		
		html += '	<td class="tdvalue '+even+'"  title="'+obj.state+'">'+obj.state+'</td>'; 
		html += '</tr>';  
	}					
	$('#tbdata').html(html);
	$('#allck').attr('checked','');
	$('.contactck').click(function(e){
		stopBubble(e);
	});
}


 

/* 移除 */
function fnCancelSelect(){

	contact_ids = [];  
	__fnBuildCurSltMan();
}
 
function fnRemoveMan(id){
	var goon = false;
  for(var i=0; i<contact_ids.length; i++){
		if(contact_ids[i].id == id){
			goon = true;
			break;
		}
	}
	if(goon){
		contact_ids = contact_ids.deleteByKey(i);
		__fnBuildCurSltMan();
		/* 看当前有没有要移除的 */
		$('#slt_'+id).attr('checked','');
	}
	
}

/* 构造当前所选 */
function __fnBuildCurSltMan(){
	$("#selectinfo_div").html('');
  
		var html='';
	 
		for(var i=0; i<contact_ids.length ; i++){
			html += '<a class="selectinfo_a contactman" href="javascript:void(0)" myid="0" title="点击删除所选" onclick="fnRemoveMan('+contact_ids[i].id+')">'+contact_ids[i].username+'('+contact_ids[i].name+')</a>';
		}
		$("#selectinfo_div").html(html);
	 
}
 
 
/* 单条选择 */
function fnSltOne(i,id){ 
	if($('#slt_'+id).attr('checked')){
		$('#slt_'+id).attr('checked','');
		
	}else{
		$('#slt_'+id).attr('checked','checked');
	}
	fnSltOne_ckb(i,id);
}
function fnSltOne_ckb(i,id){

	if($('#slt_'+id).attr('checked')){
		/* 添加 */
		 
		var addit = true; 
		for(var k=0; k<contact_ids.length; k++){
			if(contact_ids[k].id == id){
				addit = false;
				break;
			}
		}
		if(addit){ 
			contact_ids.push({
				id:id,
				name:results[i].name,
				username:results[i].username
			});
			__fnBuildCurSltMan();
		}  

	}else{
		/* 移除 */
		var goon = false;
		for(var i=0; i<contact_ids.length; i++){
			if(contact_ids[i].id == id){
				goon = true;
				break;
			}
		}
		if(goon){
			contact_ids = contact_ids.deleteByKey(i);
			__fnBuildCurSltMan();	
		}
	}
 
}

/* 选择当前页所有 */
function fnSltAll(){
	if($('#allck').attr('checked')){
		$('.contactck').attr('checked','checked');
	}else{
		$('.contactck').attr('checked','');
	}
 
	if($('#allck').attr('checked')){
		/* 添加 */  
		/* 做两个嵌套循环 oh my god */
		$('.contactck').each(function(){
			if($(this).attr('checked')){
				var goon = true; 
				for(var k=0; k<contact_ids.length; k++){
					if(contact_ids[k].id == $(this).attr('contact_id') ){
						goon = false;
						break;
					}
				}
				if(goon){ 
					contact_ids.push({
						id:$(this).attr('contact_id'),
						name:results[$(this).attr('myindex')].name,
						username:results[$(this).attr('myindex')].username
					}); 
				}  
			}
		});
		__fnBuildCurSltMan();
	}else{
		/* 做两个嵌套循环 oh my god */
		$('.contactck').each(function(){
			if(!$(this).attr('checked')){
				var goon = false; 
				for(var k=0; k<contact_ids.length; k++){
					if(contact_ids[k].id == $(this).attr('contact_id') ){
						goon = true;
						break;
					}
				}
				if(goon){
					contact_ids = contact_ids.deleteByKey(k);
				}  
			}
		});	
		__fnBuildCurSltMan();
	}
}

 

/* 选择确定动作 */
function fnOnSlt(){  
	var robj = {
		user_ids:contact_ids
	};
	if(funcname != ''){
		eval('parent.'+funcname+'(robj);');
	}
	if(typeof parent.ymPrompt == 'object'){
		parent.ymPrompt.close();
	}else{
		window.close();
	}	 
}
/* 取消 */
function fnCancel(){
	if(typeof parent.ymPrompt == 'object'){
		parent.ymPrompt.close();
	}else{
		window.close();
	}	
}
</script>
</body>
</html>